package org.example.projecttwo.service.Impl;

import org.example.projecttwo.entity.Role;
import org.example.projecttwo.mapper.RoleMapper;
import org.example.projecttwo.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author nn
 * @since 2025-11-01
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Override
    public IPage<Role> pageBy(Page<Role> page, String keyword, Integer status) {
        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();

        // 根据角色名称查询
        if (keyword != null && !keyword.isEmpty()) {
            queryWrapper.like(Role::getRoleName, keyword);
        }

        // 状态筛选
        if (status != null) {
            queryWrapper.eq(Role::getStatus, status);
        }

        return this.page(page, queryWrapper);
    }

    @Override
    public void batchUpdateStatus(List<Long> ids, Integer status) {
        this.lambdaUpdate()
                .in(Role::getId, ids)
                .set(Role::getStatus, status)
                .update();
    }
}
